

import 'package:baby/Entities/Article/Article.dart';
import 'package:baby/Entities/Article/Cover/ContentCover.dart';
import 'package:baby/Entities/Article/Cover/MusicCover.dart';
import 'package:baby/Entities/Article/Cover/QuestionAnswerCover.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_icons/font_awesome.dart';

class ArticleItem extends StatelessWidget {
	final Article article;
	final void Function() onTap;

  const ArticleItem({Key key, this.article, this.onTap}) : super(key: key);

  @override Widget build(BuildContext context) => _buildArticleItem(article);

	Widget _buildArticleItem(Article article) {
		Widget content;
		var cover = article.cover;

		var itemsHeight = 90.0;

		if (cover is ContentCover){
			content = Row(
				crossAxisAlignment: CrossAxisAlignment.center,
				children: <Widget>[
					Expanded(
						child: Column(
							crossAxisAlignment: CrossAxisAlignment.start,
							children: <Widget>[
								SizedBox(height: 5.0,),
								Text(cover.title, maxLines: 2, overflow: TextOverflow.ellipsis, style: TextStyle(height: 1.2),),
								Spacer(),
								Opacity(
									opacity: 0.6,
									child: Row(
										children: <Widget>[
											Icon(FontAwesome.getIconData("eye"), size: 16.0,),
											SizedBox(width: 3.0,),
											Text("50"),
											SizedBox(width: 10.0,),
											Icon(Icons.message, size: 16.0,),
											SizedBox(width: 3.0,),
											Text("13"),
											SizedBox(width: 10.0,),
											Icon(Icons.favorite, size: 16.0,),
											SizedBox(width: 3.0,),
											Text("12"),
											Spacer(),
										],
									),
								),
								SizedBox(height: 5.0,),
							],
						),
					),
					SizedBox(width: 10.0,),
					SizedBox(
						height: 70.0,
						child: AspectRatio(
								aspectRatio: 1.5,
								child: ClipRRect(
									borderRadius: BorderRadius.circular(5.0),
									child: CachedNetworkImage(imageUrl: cover.image, fit: BoxFit.cover, ),
								)
						),
					)
				],
			);
		}

		if (cover is MusicCover) {
			content = Row(
				children: <Widget>[
					AspectRatio(
						aspectRatio: 1.5,
						child: CachedNetworkImage(imageUrl: cover.image, fit: BoxFit.cover,),
					),
					SizedBox(width: 10.0,),
					Expanded(
							child: Text(cover.title)
					),
					IconButton(
						icon: Icon(Icons.play_arrow),
						onPressed: (){},
					)
				],
			);
		}

		if (cover is QuestionAnswerCover){
			content = Column(
				mainAxisSize: MainAxisSize.min,
				crossAxisAlignment: CrossAxisAlignment.start,
				children: <Widget>[
					Row(
						children: <Widget>[
							Chip(label: Text(cover.title, maxLines: 1, overflow: TextOverflow.ellipsis,),),
						],
					),
					Text(cover.question, maxLines: 2, overflow: TextOverflow.ellipsis,),
					SizedBox(height: 10.0,),
					Text(cover.answer, maxLines: 2, overflow: TextOverflow.ellipsis,),
					Chip(label: Text("جاۋاپ بىرىڭ"),),
				],
			);

			itemsHeight = null;
		}

		return InkWell(
			child: Container(
				height: itemsHeight,
				child: content,
			),
			onTap: onTap,
		);
	}
}
